package com.atguigu.gulimall.search.thread;


import java.util.concurrent.*;

public class ThreadTest {
    public static ExecutorService service = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("main线程开始运行");
//        Thread thread = new Thread01();
//        thread.start();

//        new Thread(new Runnable01()).start();
//        FutureTask futureTask = new FutureTask(new Callable01());
//        new Thread(futureTask).start();
//        Integer i = (Integer) futureTask.get();
//        System.out.println("main线程运行结束" + i);
        service.execute(new Runnable01());
        System.out.println("main线程运行结束");
    }

    public static class Thread01 extends Thread{
        @Override
        public void run() {
            System.out.println("线程开始运行");
            int i = 10 / 2;
            System.out.println("线程运行结束");
        }
    }

    public static class Runnable01 implements Runnable{
        @Override
        public void run() {
            System.out.println("线程开始运行");
            int i = 10 / 2;
            System.out.println("线程运行结束");
        }
    }

    public static class Callable01 implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            System.out.println("线程开始运行");
            int i = 10 / 2;
            System.out.println("线程运行结束");
            return i;
        }
    }
}
